export default {
  get_total (state) {
    // 已选中商品单价*数量
    let total = 0
    const { items } = state.cart
    const checkedItems = items.filter(item => item.checked)
    checkedItems.forEach(item => {
      total += item.minPrice * item.num
    })
    total = parseFloat(total.toFixed(2))
    state.cart.total = total
  },
  set_num (state, cart) {
    console.log('111')
    state.cart = cart
  },
  set_change (state, allChecked) {
    state.cart.allChecked = allChecked
  },
  set_allchange (state, allChecked) {
    state.cart.allChecked = allChecked
    state.cart.items.forEach(item => { item.checked = allChecked })
  },
  deled_Item (state, index) {
    state.cart.items.splice(index, 1)
  },
  add_cart (state, sku) {
    state.cart.items.unshift(sku) // items 是一个数组 数组添加方法
  },
  add_cart_num (state, index) {
    state.cart.items[index].num++
  }
}
